﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMS.BLL;
using PMS.Entity;
using PMS.Resources;
using PMS.Win;
using PMS.Utils;
using DevExpress.XtraEditors.Mask;
using PMS.DanhMucChung;
using System.Collections.Generic;
using PMS.ValidationRules;
using PMS.ReportViewer;

namespace PMS.ChucNang
{
    public partial class DoanhThuCuaSanPhamForm : FormManualBase
    {
        public DoanhThuCuaSanPhamForm(String functionID)
            : base(functionID)
        {
            InitializeComponent();
            InitStyle();
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
        }

        protected override void InitValidationRules()
        {
            base.InitValidationRules();
            Validator validate = new Validator(ValidationProvider);
            validate.AddValidationRule(new ProductValidationRules(null,false));
            SetValidator(validate,bteKhachHang);

        }

        private void InitStyle()
        {
        }

        private void btnMaThuoc_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                ProductLookup form = new ProductLookup();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (form.ProductSelected != null)
                    {
                        bteKhachHang.EditValue = form.ProductSelected.MaThuoc;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateControls())
                {
                    String sanpham = DataConvertUltils.ToString(bteKhachHang.EditValue);
                    DoanhThuCuaSanPhamViewer form = new DoanhThuCuaSanPhamViewer(sanpham, (DateTime?)dteTuNgay.EditValue, (DateTime?)dteDenNgay.EditValue);
                    form.WindowState = FormWindowState.Maximized;
                    form.StartPosition = FormStartPosition.CenterParent;
                    form.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
